package com.awakensoftware.hunterserver.repositories;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.awakensoftware.hunterserver.serverentities.TreasureTemplate;

@Repository("treasureTemplateRepository")
@Scope("singleton")
@Transactional
public class TreasureTemplateRepository extends ServerEntityRepositoryBase<TreasureTemplate> {

	@Override
	@Transactional(readOnly = true)
	public TreasureTemplate getById(long id) {
		return entityManager.find(TreasureTemplate.class, id);
	}

	// TODO: SQL Injection possible!!
	@Transactional(readOnly = true)
	public List<TreasureTemplate> searchByName(String name) {
		return entityManager
				.createQuery("SELECT t FROM TreasureTemplate t WHERE t.name LIKE :name", TreasureTemplate.class)
				.setParameter("name", "%" + name + "%").getResultList();
	}

}
